@extends('admin.master')
<script src="/js/admin/installInfos.js"></script>
@section('title', '安装信息')
	
@section('firstItem')
@parent
				<span>安装信息</span>
				<input class="a_indexbg" type="hidden" value="installinfos" />
@stop
@section('searchList')
@parent
				<a class="queryBoxBtn">搜索</a>
				<div>
					<input class="installQueryBox" type="text" placeholder="输入设备编码、用户名或经销商" value="{{ $condition }}" />
				</div>
@stop
@section('dataTables')
@parent
			<table class="installInfo dataTables" cellspacing="0" cellpadding="0">
				<thead>
					<tr>
						<td>序号</td>
						<td>设备编号</td>
						<td>用户名</td>
						<td>用户电话</td>
						<td>安装地址</td>
						<td>安装人</td>
						<td>安装人电话</td>
						<td>经销商</td>
						<td>备注信息</td>
						<td style="width:9%">安装日期</td>
						<td>安装状态</td>
						<td>编辑信息</td>
					</tr>
				</thead>
				<tbody>
					@for($i=0, $installInfoCount=count($install_infos); $i<$installInfoCount; $i++)
					<tr >
						<td>{{ $i+1 }}</td>
						<td class="DeviceCodeCell devicecodeVal">{{ $install_infos[$i]->device_code }}</td>
						<td class="UserNameCell">{{ $install_infos[$i]->customer_name }}</td>
						<td class="UserPhoneCell">{{ $install_infos[$i]->phone }}</td>
						<td class="AddressCell">{{ $install_infos[$i]->installation_address }}</td>
						<td class="MenCell">{{ $install_infos[$i]->operator }}</td>
						<td class="MenTelCell">{{ $install_infos[$i]->operator_phone }}</td>
						<td class="DealerCell">{{ $install_infos[$i]->dealer }}</td>
						<td class="other_editTextCell add_text" style="width:180px;">{{ $install_infos[$i]->remark or '' }}</td>
						<td class="YMD" style="width:160px;">{{ $install_infos[$i]->install_at->toDateString() }}</td>
						<td class="statusCell">{{ $install_infos[$i]->status }}</td>
						<td>
							<p class="cellBtn">
								<input type="hidden" value="{{ $install_infos[$i]->id }}" />
								<span class="writeBtn writeIBtn">编辑</span>
								<span class="deleteBtn deleteIBtn">删除</span>
								<input type="hidden" value="{{ $install_infos[$i]->id }}" />
							</p>
						</td>
					</tr>
					@endfor
				</tbody>
			</table>
@stop
<!-- 分页布局 -->
<!-- 添加账号 -->
@section('add_div')
	@parent
	<div class="addInfosBtn addInstallInfosBtn">添加</div>			
@stop
@section('page_num')
<ul class="pagination pagination-lg">
	<?php
	$queryParam = empty($condition)? []: ['condition' => $condition];  ?>
	{!! $install_infos->appends($queryParam)->render() !!}
</ul>			
@stop
@section('infor_promit')
@parent
	<!-- 添加安装信息弹框 -->
		<div class="editHintBox addInstallInfos">
			<div class="editBox">
				<div>
					<span>用户名</span><input class="addInstallUserName" type="text" placeholder="输入用户姓名" /><label class="required_left">*</label>
					<span class="spanR">用户电话</span><input class="addInstallUserPhone" type="text" placeholder="输入用户手机号码"/><label class="required_right">*</label>
				</div>
				<div style="margin: 15px 0;">
					<span>安装地址</span><input class="addInstallAddress" type="text" placeholder="输入安装地址" /><label class="required_left">*</label>
					<span class="spanR">设备编号</span><input class="addIDeviceCode" type="text" placeholder="输入设备编号"/><label class="required_right">*</label>
				</div>
				<div class="p_relative">
					<span>安装状态</span><label style="position: absolute;top: 0;left: 270px;" class="required_left">*</label>
					<input class="editIStatus addInstallStatus" />
					<div class="statusDropBox addsDropBox">
						<a>已安装</a>
						<a>未安装</a>
					</div>
					<span class="spanR" style="position: absolute;top: 0;left: 280px;">经销商</span>
					<input style="position: absolute;top: 0;left: 380px;" class="addInstallDealer" type="text" placeholder="输入经销商" oninput="dealerFn('.addInstallDealer','.addDealerList')" /><label style="position: absolute;top: 0;left: 570px;" class="required_right">*</label>
					<div class="addDealerList" style="left: 380px;"></div>
				</div>
				<div class="inputListBox">
					<span>安装人</span><input class="addInstallMen" type="text" placeholder="输入安装姓名" oninput="InstallerFn('.addInstallMen','.addInstallMenList','.spanR');"/><label class="required_left">*</label>
					<div class="addInstallMenList"></div>
					<span class="spanR">安装人电话</span><input class="addInstallMenTel" type="text" placeholder="输入安装人手机号码"/><label class="required_right">*</label>
				</div>
				<div style="margin: 15px 0;">
					<span style="width:75px">安装日期</span>
					<input type="text" id="addInstallInfosDate" placeholder="添加安装日期" onclick="layui.laydate({elem: this,istime: 1, format: 'YYYY-MM-DD' })"/>
					<label class="required_left">*</label>
				</div>
				<p><textarea class="textareaBox other_addText" placeholder="备注信息："></textarea></p>
				<div><label class="labelBox" id="addIlabelBox"></label></div>
			</div>
			<div class="btnBox" >
				<a class="addINoBtn">取消</a>
				<a class="addIOkBtn">确定</a>
			</div>
		</div>
	<!-- 编辑维护信息弹框 -->
		<div class="editHintBox editInstallInfos">
			<div class="editBox">
				<div>
					<span>用户名</span><input class="editIUserName" type="text"  /><label class="required_left">*</label>
					<span class="spanR">用户电话</span><input class="editIUserPhone" type="text" /><label class="required_right">*</label>
				</div>
				<div style="margin:15px 0;">
					<span>安装地址</span><input class="editIAddress" type="text"/><label class="required_left">*</label>
					<span class="spanR">设备编号</span><input class="editIDeviceCode" type="text" /><label class="required_right">*</label>
				</div>
				<div class="p_relative">
					<span>安装状态</span><label style="position: absolute;top: 0;left: 270px;" class="required_left">*</label>
					<input class="editIStatus sBox" />
					<div class="statusDropBox sDropBox">
						<a>已安装</a>
						<a>未安装</a>
					</div>
					<span class="spanR" style="position: absolute;top: 0;left: 280px;">经销商</span><input style="position: absolute;top: 0;left: 380px;" class="editIDealer" type="text" oninput="dealerFn('.editIDealer','.editDealerList')" /><label style="position: absolute;top: 0;left: 570px;" class="required_right">*</label>		
					<div class="editDealerList" style="left: 380px;"></div>		
				</div>
				<div class="inputListBox">
					<span>安装人</span>
					<input class="editIMen" type="text" style="margin-left: -5px;" oninput="InstallerFn('.editIMen','.installMenList','.spanR');"  />
					<label class="required_left">*</label>
					<div class="installMenList"></div>
					<span class="spanR" style="margin-right: 15px;">安装人电话</span><input class="editIMenTel" type="text" /><label class="required_right">*</label>
				</div>
				<div style="margin: 15px 0;">
					<span style="width:75px">安装日期</span>
					<input type="text" id="editInstallInfosDate" placeholder="输入安装日期" onclick="layui.laydate({elem: this,istime: 1, format: 'YYYY-MM-DD' })"/>
					<label class="required_left">*</label>
				</div>
				<p><textarea class="textareaBox other_editText" placeholder="备注信息："></textarea></p>
				<div><label class="labelBox" id="editIlabelBox"></label></div>
			</div>
			<div class="btnBox" >
				<a class="editINoBtn">取消</a>
				<a class="editIOkBtn">确定</a>
			</div>
		</div>
	<!-- 删除维护信息弹框 -->
	<div class="deleteIInfos">
		<div class="titleText">是否删除此条安装信息？</div>
		<label class="labelBox" id="deleteIlabelBox"></label>
		<div class="btnBox">
			<a class="deleteICancelBtn">取消</a>
			<a class="okBtn deleteIOkBtn">确定</a>
		</div>
	</div>
	<script type="text/javascript">
	function InstallerFn(installMen,installMenList,telNum){
		$(installMenList).show();
		$.ajax({
			url:"/admin/api/device/installers",
			type:"get",
			dataType:"json",
			success:function(data){
				if(data.status.errCode==0){
					var content = '';
					var aOperator=[];
					var aOperator_phone=[];
					for(var i=0;i<data.data.length;i++){
						content = content+'<a><span class="operator" style="display: inline;">'+data.data[i].operator+' </span> <span class="operator_phone">'+data.data[i].operator_phone+'</span></a>'
						aOperator[i]=data.data[i].operator;
						aOperator_phone[i]=data.data[i].operator_phone;
					};
					var kw = jQuery.trim($(installMen).val());
					if(kw==""){
						$(installMenList).html(content);
					}else{
						var html = "";
						for (var j = 0; j <data.data.length; j++) {
							if (aOperator[j].indexOf(kw) >= 0) {
								html = html+'<a><span class="operator" style="display: inline;">'+aOperator[j]+' </span> <span class="operator_phone">'+aOperator_phone[j]+'</span></a>'
							}
						}
						$(installMenList).html(html);
					}
					$(installMenList).children("a").unbind('click').click(function(){
						$(installMen).val($(this).children(".operator").html());
						$(telNum).val($(this).children(".operator_phone").html());
						$(installMenList).hide();
					})
					$("body").unbind('click').click(function(){
						$(installMenList).hide();
					});
				}else{
					hint(data.status.message);
				}
			},
		});	
	}
	function dealerFn(dealer,dealerList){
		$(dealerList).show();
		$.ajax({
			url:"/admin/api/device/dealers",
			type:"get",
			dataType:"json",
			success:function(data){
				if(data.status.errCode==0){
					var content = '';
					var aDealers=[];
					for(var i=0;i<data.data.length;i++){
						content = content+'<a>'+data.data[i].dealer+'</a>';
						aDealers[i]=data.data[i].dealer;
					};
					var kw = jQuery.trim($(dealer).val());
					if(kw==""){
						$(dealerList).html(content);
					}else{
						var html = "";
						for (var j = 0; j <data.data.length; j++) {
							if (aDealers[j].indexOf(kw) >= 0) {
								html = html+'<a>'+aDealers[j]+'</a>'
							}
						}
						$(dealerList).html(html);
					}
					$(dealerList).children("a").unbind('click').click(function(){
						$(dealer).val($(this).html());
						$(dealerList).hide();
					});
					$("body").unbind('click').click(function()
					{
						$(dealerList).hide();
					});
				}else{
					hint(data.status.message);
				}
			}
		});	
	}
</script>
@stop

